location | NN 2 IE 3 DOM 1 | ||||
There is one location object in each window or frame. The object stores all information about the URL of the document currently loaded into that window or frame. By assigning a new URL to the href property of the location object, you instruct the browser to load a new page into the window or frame. This is the primary way of scripting the loading of a new page: location.href = "newPage.html" A script in one frame can reference the location object in another frame to load a new document into that other frame: parent.otherFrameName.location.href = "newPage.html" Security restrictions prevent a script in one frame from accessing location object information in another frame if the document in the second frame does not come from the same domain as the document with the nosy script. This prevents a rogue script from monitoring navigation in another frame to external web sites. In Navigator 4, you can overcome the security restriction with the help of signed scripts (a topic more suitable for a JavaScript book covering Navigator 4), but the user still has to give explicit permission for a script to access location object information outside the script's domain. | |||||
Object Model Reference
|
hash | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
That portion of a URL following the # symbol, referring to an anchor location in a document. This property contains its data only if the user has explicitly navigated to an anchor, and is not just scrolling to it. Do not include the # symbol when setting the property. | |||
Examplelocation.hash = "section3" | |||
Value String. | |||
|
host | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The combination of the hostname and port (if any) of the server that serves up the current document. If the port is explicitly part of the URL, the hostname and port are separated by a colon, just as they are in the URL. | |||
Exampleif (location.host = "www.megacorp.com:80") { ... } | |||
Value String of hostname, optionally followed by a colon and port number. | |||
|
hostname | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The combination of the hostname of the server (i.e., a "two-dot" address consisting of server name and domain) that serves up the current document. The hostname property does not include the port number. | |||
Exampleif (location.hostname = "www.megacorp.com") { ... } | |||
Value String of hostname (server and domain). | |||
|
href | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The complete URL of the document loaded in the window or frame. Assigning a URL to this property is how you script navigation to load a new document into the window or frame (although Internet Explorer also offers the equivalent window.navigate( ) method). | |||
Examplelocation.href = "http://www.megacorp.com" | |||
Value String of complete or relative URL. | |||
|
pathname | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The pathname component of the URL. This consists of all URL information following the last character of the domain name, including the initial forward slash symbol. | |||
Examplelocation.pathname = "/images/logoHiRes.gif" | |||
Value String. | |||
|
port | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The port component of the URL, if one exists. This consists of all URL information following the colon after the last character of the domain name. The colon is not part of the port property value. | |||
Examplelocation.port = "80" | |||
Value String (a numeric value as string). | |||
|
protocol | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The protocol component of the URL. This consists of all URL information up to and including the first colon of a URL. Typical values are: "http:", "file:", "ftp:", and "mailto:". | |||
Exampleif (location.protocol == "file:") { } | |||
Value String. | |||
|
search | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The URL-encoded portion of a URL that begins with the ? symbol. A document that is served up as the result of the search also may have the search portion available as part of the window.location property. You can modify this property by script. Doing so sends the URL and search criteria to the server. You must know the format of data (usually name/value pairs) expected by the server to perform this properly. | |||
Examplelocation.search="?p=Tony+Blair&d=y&g=0&s=a&w=s&m=25" | |||
Value String starting with the ? symbol. | |||
|
assign( ) | NN 2 IE 3 DOM n/a | ||
assign("URL") This method was intended to be hidden from view of scripters, but remains available for now. It performs the same action as assigning a URL to the location.href property. The assign( ) method is listed here for completeness and should not be used. | |||
Returned Value None. | |||
Parameters
|
reload( ) | NN 3 IE 4 DOM 1 | ||
reload([unconditional]) Performs a hard reload of the document associated with the location object. This kind of reload resets form elements to their default values (for a soft reload, use history.go(0)). By default the reload( ) method performs a conditional-GET action, which retrieves the file from the browser cache if the file is still in the cache (and the cache is turned on). To force a reload from the server, force an unconditional-GET by adding the true Boolean parameter. | |||
Returned Value None. | |||
Parameters
|
replace( ) | NN 3 IE 4 DOM 1 | ||
replace("URL") Loads a new document into the reference window and replaces the
browser's history listing entry of the current document with
the entry of the new document. Thus, some interim page that you
don't want appearing in history (to prevent the | |||
Returned Value None. | |||
Parameters
|